<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs v-model="actives" @tab-click="tabClick">
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form :model="formData" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:">
                <el-input v-model="formData.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click=" saveUserDetail">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <UserInfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
import { getDetail } from '@/api/user'
import { saveUserDetail } from '@/api/employees'
import JobInfo from './components/JobInfo'
import UserInfo from './components/UserInfo'
export default {
  components: { JobInfo, UserInfo },
  data() {
    return {
      formData: {},
      actives: Cookie.get('actives') || '0'
    }
  },
  created() {
    this.getUserInfo()
  },

  methods: {
    async getUserInfo() {
      const res = await getDetail(this.$route.params.id)
      console.log(res)
      this.formData = { ...res, password: '' }
    },

    async saveUserDetail() {
      await saveUserDetail(this.formData)
      this.getUserInfo()
      this.$message.success('更新成功')
    },
    tabClick() {
      Cookie.set('actives', this.actives)
    }
  }
}
</script>

<style>

</style>
